﻿using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using T68Control.S12L_M1;

namespace T68Control.Procdure
{
    internal class XlsxTestReportGenerator : ITestReportGenerator
    {
        public void GenerateReport(List<string> headers, List<TestData> data, string filePath)
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            using (var package = new ExcelPackage())
            {
                var worksheet = package.Workbook.Worksheets.Add("测试结果");
                for (int i = 0; i < headers.Count; i++)
                {
                    worksheet.Cells[1, i + 1].Value = headers[i];
                }

                var rowIndex = 2;
                foreach (var item in data)
                {
                    worksheet.Cells[rowIndex, 1].Value = item.SN;
                    worksheet.Cells[rowIndex, 2].Value = item.TotalResult;
                    worksheet.Cells[rowIndex, 3].Value = item.TestTime;
                    worksheet.Cells[rowIndex, 4].Value = item.No;
                    worksheet.Cells[rowIndex, 5].Value = item.Desc;
                    worksheet.Cells[rowIndex, 6].Value = item.PassCondition;
                    worksheet.Cells[rowIndex, 7].Value = item.Result;
                    worksheet.Cells[rowIndex, 8].Value = item.Message;

                    rowIndex++;
                }

                var fileInfo = new FileInfo(filePath);
                package.SaveAs(fileInfo);
            }
        }

        public void GenerateReport(List<string> headers, List<TestItem2> data, string filePath)
        {
            throw new NotImplementedException();
        }
    }
}